package sketch.specs;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.jdt.core.dom.Block;

import sketch.ast.ASTUtils;
import sketch.specs.annotation.ChooseAll;
import sketch.util.Checker;

public class SketchedChooseAllBlock extends SketchedBlock {
	
	public static final String COMMENT_REPRESENTATION = ChooseAll.value();//"@ChooseAll";
	
	public static final String COMMENT_REPRESENTATION_ALIAS = ChooseAll.alias(); //@ChooseAllOrNone

	public SketchedChooseAllBlock(Block realBlock) {
		super(realBlock);
	}

	@Override
	protected List<Block> replicate() {
		List<Block> retBlocks = new LinkedList<Block>();
		
		Block fullReplicate = ASTUtils.deepClone(this.realBlock);
		Block wrap_replicate = fullReplicate.getAST().newBlock();
		fullReplicate.delete();
		wrap_replicate.statements().add(fullReplicate);
		retBlocks.add(wrap_replicate);
		if(!this.realBlock.statements().isEmpty()) {
			Block emptyBlock = ASTUtils.deepClone(this.realBlock);
			emptyBlock.statements().clear();
			retBlocks.add(emptyBlock); 
		}
		Checker.checkTrue(retBlocks.size() == 1 || retBlocks.size() == 2, "the size of ret block list: "
				+ retBlocks.size() + " is not correct.");
		
		return retBlocks;
	}

	@Override
	protected SketchedBlock newInstance(Block block) {
		return new SketchedChooseAllBlock(block);
	}

}
